﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.MaterialDocVMs
{
    public partial class MaterialDocListVM : BasePagedListVM<MaterialDoc_View, MaterialDocSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MaterialDoc_View>> InitGridHeader()
        {
            return new List<GridColumn<MaterialDoc_View>>{
                
                this.MakeGridHeader(x => x.MaterialDoc_Code).SetTitle(@Localizer["Page.物料编码"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Name).SetTitle(@Localizer["Page.物料名称"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Spec).SetTitle(@Localizer["Page.物料规格"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Unit).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_ErpCode).SetTitle(@Localizer["Page.Erp编码"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_MaterialProperty).SetTitle(@Localizer["Page.物料属性"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_MaterialType).SetTitle(@Localizer["Page.物料类型"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Expiration).SetTitle(@Localizer["Page.保质期"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Rules).SetTitle(@Localizer["Page.条码校验规则"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Supplier).SetTitle(@Localizer["Page.物料供应商"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Pos).SetTitle(@Localizer["Page.存放位置"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MaterialDoc_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MaterialDoc_View> GetSearchQuery()
        {
            var query = DC.Set<MaterialDoc>()
                
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Spec, x=>x.Spec)
                .CheckContain(Searcher.Unit, x=>x.Unit)
                .CheckContain(Searcher.ErpCode, x=>x.ErpCode)
                .CheckEqual(Searcher.MaterialProperty, x=>x.MaterialProperty)
                .CheckEqual(Searcher.MaterialType, x=>x.MaterialType)
                .CheckEqual(Searcher.Expiration, x=>x.Expiration)
                .CheckContain(Searcher.Supplier, x=>x.Supplier)
                .CheckContain(Searcher.Pos, x=>x.Pos)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MaterialDoc_View
                {
				    ID = x.ID,
                    
                    MaterialDoc_Code = x.Code,
                    MaterialDoc_Name = x.Name,
                    MaterialDoc_Spec = x.Spec,
                    MaterialDoc_Unit = x.Unit,
                    MaterialDoc_ErpCode = x.ErpCode,
                    MaterialDoc_MaterialProperty = x.MaterialProperty,
                    MaterialDoc_MaterialType = x.MaterialType,
                    MaterialDoc_Expiration = x.Expiration,
                    MaterialDoc_Rules = x.Rules,
                    MaterialDoc_Supplier = x.Supplier,
                    MaterialDoc_Pos = x.Pos,
                    MaterialDoc_Active = x.Active,
                    MaterialDoc_CreateTime = x.CreateTime,
                    MaterialDoc_UpdateTime = x.UpdateTime,
                    MaterialDoc_CreateBy = x.CreateBy,
                    MaterialDoc_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class MaterialDoc_View: MaterialDoc
    {
        
        public string MaterialDoc_Code { get; set; }
        public string MaterialDoc_Name { get; set; }
        public string MaterialDoc_Spec { get; set; }
        public string MaterialDoc_Unit { get; set; }
        public string MaterialDoc_ErpCode { get; set; }
        public MaterialPropertyEnum? MaterialDoc_MaterialProperty { get; set; }
        public MaterialClassifyEnum? MaterialDoc_MaterialType { get; set; }
        public int? MaterialDoc_Expiration { get; set; }
        public string MaterialDoc_Rules { get; set; }
        public string MaterialDoc_Supplier { get; set; }
        public string MaterialDoc_Pos { get; set; }
        public bool? MaterialDoc_Active { get; set; }
        public DateTime? MaterialDoc_CreateTime { get; set; }
        public DateTime? MaterialDoc_UpdateTime { get; set; }
        public string MaterialDoc_CreateBy { get; set; }
        public string MaterialDoc_UpdateBy { get; set; }

    }

}